package com.xqb.modules.controller.market;

import com.xqb.common.annotation.Log;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.common.enums.BusinessType;
import com.xqb.common.utils.poi.ExcelUtil;
import com.xqb.modules.domain.po.MktPromotion;
import com.xqb.modules.service.IMktPromotionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 促销活动Controller
 * 
 * @author xqb
 * @date 2024-10-15
 */
@RestController
@RequestMapping("/market/promotion")
public class MktPromotionController extends BaseController
{
    @Autowired
    private IMktPromotionService mktPromotionService;

    /**
     * 查询促销活动列表
     */
    @PreAuthorize("@ss.hasPermi('market:promotion:list')")
    @GetMapping("/list")
    public TableDataInfo list(MktPromotion mktPromotion)
    {
        startPage();
        List<MktPromotion> list = mktPromotionService.selectMktPromotionList(mktPromotion);
        return getDataTable(list);
    }

    /**
     * 导出促销活动列表
     */
    @PreAuthorize("@ss.hasPermi('market:promotion:export')")
    @Log(title = "促销活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MktPromotion mktPromotion)
    {
        List<MktPromotion> list = mktPromotionService.selectMktPromotionList(mktPromotion);
        ExcelUtil<MktPromotion> util = new ExcelUtil<MktPromotion>(MktPromotion.class);
        util.exportExcel(response, list, "促销活动数据");
    }

    /**
     * 获取促销活动详细信息
     */
    @PreAuthorize("@ss.hasPermi('market:promotion:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mktPromotionService.selectMktPromotionById(id));
    }

    /**
     * 新增促销活动
     */
    @PreAuthorize("@ss.hasPermi('market:promotion:add')")
    @Log(title = "促销活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MktPromotion mktPromotion)
    {
        return toAjax(mktPromotionService.insertMktPromotion(mktPromotion));
    }

    /**
     * 修改促销活动
     */
    @PreAuthorize("@ss.hasPermi('market:promotion:edit')")
    @Log(title = "促销活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MktPromotion mktPromotion)
    {
        return toAjax(mktPromotionService.updateMktPromotion(mktPromotion));
    }

    /**
     * 删除促销活动
     */
    @PreAuthorize("@ss.hasPermi('market:promotion:remove')")
    @Log(title = "促销活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mktPromotionService.deleteMktPromotionByIds(ids));
    }
}
